<template>
	<view class="">
		<view class="scroll-font" v-if="scrollFontList.length>0">
			<swiper class="zimu" :indicator-dots="false" :autoplay="auto" :interval="interval" :duration="duration"
				:circular="true" :vertical="true" :acceleration='true' :disable-touch="true" @change="change">
				<swiper-item v-for="(item,index) in scrollFontList" :key="index">
					<view :class="['zimu-item',(item.type==1&&'tongbao')||'togao']">
						<image src="/static/icon3/laba.png" mode=""></image>
						<text>{{(item.type==0&&'公告：')||'通报：'}}</text>
						<text class="zimu-item-name">{{item.realName}}</text><text>
							{{item.dataText}}</text>
					</view>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>
<script>
	export default {
		name: 'swiperTip',
		inject: ['zimuAutoplay'],
		data() {
			return {
				scrollFontList: [], //滚动字幕
				auto: true,
				interval: 2000,
				duration: 1500,
			}
		},
		methods: {
			change(e) {
				if (this.scrollFontList[e.detail.current].type == 1) {
					this.interval = 4000
				} else {
					this.interval = 2000
				}
			},
			async getUserAccountList() {
				let res = await this.$fetch(this.$api.getUserAccountList, {}, 'POST')
				if (res.code) return uni.showToast({
					title: res.msg,
					icon: 'none'
				})
				this.scrollFontList = res.data
				uni.setStorageSync('UserAccountList', res.data)
			}
		},
		mounted() {
			this.auto = this.zimuAutoplay
			let c = new Date().getDate()
			if (uni.getStorageSync('getUserAccountListTime')) {
				if (c == uni.getStorageSync('getUserAccountListTime')) {
					this.scrollFontList = uni.getStorageSync('UserAccountList')
				} else {
					this.getUserAccountList()
				}
			} else {
				this.getUserAccountList()
			}
			uni.setStorageSync('getUserAccountListTime', c)
		}
	}
</script>
<style lang="scss" scoped>
	.togao {
		background-color: rgba(255, 241, 191, 1);
		color: #262626;
	}

	.tongbao {
		background-color: rgba(254, 69, 56, 0.1);
		color: #FE4538;
	}

	.scroll-font {
		height: 64rpx;
		display: flex;
		align-items: center;
		width: 100%;
		box-sizing: border-box;

		.zimu {
			width: 100%;
			height: 64rpx;

			.zimu-item {
				width: 100%;
				height: 64rpx;
				line-height: 64rpx;
				font-size: 28rpx;
				display: flex;
				align-items: center;

				image {
					width: 28rpx;
					height: 28rpx;
					margin: 0 30rpx;
				}

				.zimu-item-name {
					margin-right: 30rpx;
				}
			}
		}
	}
</style>